<template>
  <div class="company-dialog">
    <el-dialog :visible.sync="visible"
               :title="title"
               width="60%"
               :before-close="modalClose"
               center
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form :model="company"
               label-width="200px"
               ref="formValidate"
               :rules="ruleValidate">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公司性质:"
                          prop="hospitalType">
              <el-select v-model="company.hospitalType"
                         clearable
                         class="w-200"
                         placeholder="请选择公司性质"
                         @change="changeNature">
                <el-option v-for="item in natureList"
                           :key="item.value"
                           :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="简称:"
                          prop="shortName">
              <el-input v-model="company.shortName"
                        class="w-200"
                        placeholder="请填写简称"
                        clearable></el-input>
            </el-form-item>
            <el-form-item label="法人姓名:"
                          prop="legalName">
              <el-input v-model="company.legalName"
                        placeholder="请填写法人姓名"
                        class="w-200"
                        clearable></el-input>
            </el-form-item>
<!--            <el-form-item label="账号:"-->
<!--                          prop="account">-->
<!--              <el-input v-model="company.account"-->
<!--                        placeholder="请填写账号"-->
<!--                        class="w-200"-->
<!--                        clearable></el-input>-->
<!--            </el-form-item>-->
            <el-form-item label="账号有效期:"
                          prop="accountExpire">
              <el-input v-model="company.accountExpire"
                        placeholder="请填写有效期"
                        class="w-200"
                        clearable>
                <el-button slot="append">月</el-button>
              </el-input>
            </el-form-item>

            <el-form-item label="开通的业务:">
              <el-checkbox v-model="company.isOpenCdp" :label="1" :false-label="0" :true-label="1">专病慢病签约服务
              </el-checkbox>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="公司名称:"
                          prop="hospitalId">
              <el-select v-model="company.hospitalId"
                         filterable
                         remote
                         reserve-keyword
                         clearable
                         :remote-method='remoteMethod'
                         placeholder="请输入公司名称"
                         :loading="loading2"
                         class="w-200"
                         :disabled="isDisabled"
                         @change="changeCompany">
                <el-option v-for="option in companyFilterList"
                           :value="option.id"
                           :label="option.name"
                           :key="option.id"></el-option>
              </el-select>
              <p style="color:#F56C6C">查询后如没有结果，请操作人员去医院列表添加!</p>
            </el-form-item>
            <el-form-item label="法人电话:"
                          prop="phone">
              <el-input v-model="company.phone"
                        placeholder="请填写法人电话"
                        class="w-200"
                        auto-complete="new-phone"
                        clearable></el-input>
            </el-form-item>
<!--            <el-form-item label="密码:"-->
<!--                          prop="password">-->
<!--              <el-input type="password"-->
<!--                        v-model="company.password"-->
<!--                        placeholder="请输入密码"-->
<!--                        class="w-200"-->
<!--                        auto-complete="new-password"-->
<!--                        clearable></el-input>-->
<!--              <p style="color:#F56C6C"-->
<!--                 v-if="this.companyDialog">修改时,因密码是采用加密的,请重新输入密码再提交!</p>-->
<!--            </el-form-item>-->

          </el-col>
        </el-row>
        <!-- 服务产品赠送 -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="服务产品赠送:">
              <el-button type="primary"
                         @click="handleAddProduct">新增
              </el-button>
              <el-table border
                        class="mt-20"
                        :data="company.servicePackageDtos">
                <el-table-column label="产品包名称">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.servicePackageId"
                               placeholder="请选择产品包名称"
                               filterable
                               :disabled="scope.row.newData!==1"
                               @change="changePackageName(scope.$index, scope.row)">
                      <el-option v-for="item in packageList"
                                 :key="item.servicePackageId"
                                 :label="item.packageName"
                                 :value="item.servicePackageId">
                      </el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="价格">
                  <template slot-scope="scope">
                    <el-input-number v-model="scope.row.price"
                                     :controls="false"
                                     :min="0"
                                     :precision="2"
                                     type="number"
                                     :disabled="scope.row.newData!==1"
                                     placeholder="请输入价格"></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column label="赠送数量">
                  <template slot-scope="scope">
                    <el-input-number v-model="scope.row.count"
                                     :controls="false"
                                     :min="0"
                                     :precision="0"
                                     type="number"
                                     :disabled="scope.row.newData!==1"
                                     placeholder="请输入赠送数量"></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column label="操作"
                                 width="100">
                  <template slot-scope="scope">
                    <el-button size="mini"
                               type="danger"
                               :disabled="scope.row.newData!==1"
                               @click="handleDelete(scope.$index)">删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="微信开放平台:"></el-form-item>-->
        <!--            <el-form-item label="appid:"-->
        <!--                          prop="weChatAppId">-->
        <!--              <el-input v-model="company.weChatAppId"-->
        <!--                        class="w-200"-->
        <!--                        placeholder="请填写appid"-->
        <!--                        clearable></el-input>-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="APPID密码:"-->
        <!--                          prop="weChatAppKey">-->
        <!--              <el-input v-model="company.weChatAppKey"-->
        <!--                        class="w-200"-->
        <!--                        placeholder="请填写APPID密码"-->
        <!--                        clearable></el-input>-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="API KEY:"-->
        <!--                          prop="weChatAppSecret">-->
        <!--              <el-input v-model="company.weChatAppSecret"-->
        <!--                        class="w-200"-->
        <!--                        placeholder="请填写API KEY"-->
        <!--                        clearable></el-input>-->
        <!--            </el-form-item>-->
        <el-form-item label="公司logo:"
                      prop="imageUrl">
          <el-upload :action="fileLogoUploadAction"
                     :max-size="fileMaxSize"
                     class="avatar-uploader"
                     :show-file-list="false"
                     :on-exceeded-size="showError"
                     :on-success="uploadLogoSuccess">
            <el-image v-if="company.imageUrl" :src="company.imageUrl"  class="avatar"/>
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>

        </el-form-item>
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="支付宝:"></el-form-item>-->
        <!--            <el-form-item label="appid:"-->
        <!--                          prop="appId">-->
        <!--              <el-input v-model="company.appId"-->
        <!--                        class="w-200"-->
        <!--                        placeholder="请填写appid"-->
        <!--                        clearable></el-input>-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="私钥:"-->
        <!--                          prop="appKey">-->
        <!--              <el-input v-model="company.appKey"-->
        <!--                        class="w-200"-->
        <!--                        placeholder="请填写appKey"-->
        <!--                        clearable></el-input>-->
        <!--            </el-form-item>-->
        <!--            <el-form-item label="公钥:"-->
        <!--                          prop="appSecret">-->
        <!--              <el-input v-model="company.appSecret"-->
        <!--                        class="w-200"-->
        <!--                        placeholder="请填写公钥"-->
        <!--                        clearable></el-input>-->
        <!--            </el-form-item>-->
        <el-form-item label="营业执照:"
                      prop="licenseUrl">
          <el-upload :action="fileLogoUploadAction"
                     :max-size="fileMaxSize"
                     class="avatar-uploader"
                     :show-file-list="false"
                     :on-exceeded-size="showError"
                     :on-success="uploadLicenseSuccess">
            <img v-if="company.licenseUrl" :src="company.licenseUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <!--          </el-col>-->
        <!--        </el-row>-->
        <el-row v-if="company.isOpenCdp==1">
          <el-col :span="12">
            <el-form-item label="慢病包最低服务费-无合并症:"
                          prop="lowestServicePrice"
                          :rules="company.isOpenCdp==1?ruleValidate.lowestServicePrice:[{required: false}]"
                          v-if="company.isOpenCdp==1">
              <el-input v-model="company.lowestServicePrice"
                        placeholder="请填写服务费"
                        class="w-200"
                        clearable>
                <el-button slot="append">元</el-button>
              </el-input>
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <el-form-item label="慢病包最低服务费-有合并症:"
                          prop="lowestComplicationServicePrice"
                          :rules="company.isOpenCdp==1?ruleValidate.lowestComplicationServicePrice:[{required: false}]"
                          v-if="company.isOpenCdp==1">
              <el-input v-model="company.lowestComplicationServicePrice"
                        placeholder="请填写服务费"
                        class="w-200"
                        clearable>
                <el-button slot="append">元</el-button>
              </el-input>
            </el-form-item>

          </el-col>
        </el-row>
        <el-row v-if="company.isOpenCdp==1">
          <el-col :span="12">
            <el-form-item label="慢病包最低价格:"
                          prop="lowestPrice">
              <el-input placeholder="请填写最低价格"
                        v-model="company.lowestPrice"
                        class="w-200"
                        clearable>
                <el-button slot="append">元</el-button>
              </el-input>


            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预付定金比例:"
                          prop="depositRatio">
              <el-input v-model="company.depositRatio"
                        placeholder="请填写定金比例"
                        class="w-200"
                        clearable>
                <el-button slot="append">%</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="company.isOpenCdp==1">
          <el-col :span="12">
            <el-form-item label="签约奖励比例:"
                          prop="signRewardRatio">
              <el-input placeholder="请填写签约奖励比例"
                        v-model.number="company.signRewardRatio"
                        class="w-200"
                        type="number"
                        clearable>
                <el-button slot="append">%</el-button>
              </el-input>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="完成必测项目检查奖励比例:"
                          prop="detectRewardRatio">
              <el-input v-model.number="company.detectRewardRatio"
                        placeholder="请填写比例"
                        class="w-200"
                        type="number"
                        clearable>
                <el-button slot="append">%</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="company.isOpenCdp==1">
          <el-col :span="12">
            <el-form-item label="完成医生咨询比例:"
                          prop="consultDoctorRatio">
              <el-input placeholder="请填写比例"
                        v-model.number="company.consultDoctorRatio"
                        class="w-200"
                        type="number"
                        clearable>
                <el-button slot="append">%</el-button>
              </el-input>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="续签比例:"
                          prop="accountExpire">
              <el-input v-model.number="company.renewalRewardRatio"
                        placeholder="请填写比例"
                        class="w-200"
                        type="number"
                        clearable>
                <el-button slot="append">%</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="company.isOpenCdp==1">
          <el-col :span="24">
            <el-form-item label="天下医生签单红包:"
                          prop="txSignReward">
              <el-input placeholder="请填写签单红包"
                        v-model="company.txSignReward"
                        class="w-200"
                        clearable>
                <el-button slot="append">元</el-button>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="分店账户数:"
                          prop="branchAccountCount">
              <el-input placeholder="请填写分店账户数"
                        v-model="company.branchAccountCount"
                        class="w-200"
                        clearable></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="行政区域:"
                          prop="provinceId">
              <el-select v-model="company.provinceId"
                         class="w-200"
                         @change="selectChildren1">
                <el-option v-for="item in provinceList"
                           :value="item.id"
                           :label="item.name"
                           :key="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="cityId">
              <el-select v-model="company.cityId"
                         class="w-200"
                         @change="selectChildren2">
                <el-option v-for="item in cityList"
                           :value="item.id"
                           :label="item.name"
                           :key="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item prop="districtId">
              <el-select v-model="company.districtId"
                         class="w-200"
                         @change="selectChildren3">
                <el-option v-for="item in districtList"
                           :value="item.id"
                           :label="item.name"
                           :key="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="18">
            <el-form-item label="详细地址:"
                          prop="address">
              <el-input v-model="company.address"
                        type="textarea"
                        placeholder="请填写详细地址"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <p align="center">
        <el-button type="primary"
                   @click="saveData">保 存
        </el-button>
        <el-button @click="modalClose"
                   style="margin-left: 8px">取 消
        </el-button>
      </p>
    </el-dialog>
  </div>
</template>
<script>
import md5 from "js-md5";

export default {
  name: 'companyDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    companyDialog: {
      type: Object,
      default: false
    }
  },
  data() {
    // 法人电话
    const pwdValidate = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("手机号不能为空"));
      } else if (!/^1[3456789]\d{9}$/.test(value)) {
        callback("手机号格式不正确");
      } else {
        this.$refs.formValidate.validateField("account");
        callback();
      }
    };
    // 账号
    const pwdCheckValidate = (rule, value, callback) => {
      if (this.company.phone != "" && value == '') {
        callback(new Error("账号不能为空"));
      } else {
        callback();
      }
    };
    return {
      title: '新 增',
      loading2: false,
      isDisabled: false,
      fileMaxSize: 1024 * 50,
      fileLogoUploadAction: '',
      fileLicenseUploadAction: '',
      natureList: [
        {label: '药店', value: 1},
        {label: '诊所', value: 2}
      ],
      provinceList: [],
      cityList: [],
      districtList: [],
      packageList: [], // 产品包名称列表
      companyList: [],
      companyFilterList: [],
      company: {
        id: '',
        name: '',  // 公司名称
        shortName: '',  // 简称
        hospitalId: '', // 公司名称Id
        hospitalType: null, // 公司性质
        legalName: '',
        phone: '',
        // account: '', // 账号
        // password: '',
        accountExpire: '', // 账号有效期
        appId: '',
        appKey: '',
        appSecret: '',
        weChatAppId: '',
        weChatAppKey: '',
        weChatAppSecret: '',
        imageUrl: '',
        licenseUrl: '',
        branchAccountCount: '', // 分店账户数
        provinceId: '',
        cityId: '',
        districtId: '',
        address: '',
        servicePackageDtos: [], // 服务产品赠送
        isOpenCdp: 0,
        lowestServicePrice: '',
        lowestComplicationServicePrice: '',
        lowestPrice: '',
        depositRatio: '',
        signRewardRatio: '',
        detectRewardRatio: '',
        consultDoctorRatio: '',
        renewalRewardRatio: '',
        txSignReward: ''
      },
      // 表单校验
      ruleValidate: {
        hospitalType: [{required: true, message: '请选择公司性质', trigger: 'change'}],
        legalName: [
          {required: true, message: '请填写法人姓名', trigger: 'blur'},
          {type: 'string', max: 10, message: '请输入10字以内', trigger: 'blur'}
        ],
        // account: [{required: true, validator: pwdCheckValidate, trigger: 'blur'}],
        hospitalId: [{required: true, message: '请填写公司名称', trigger: 'blur'}],
        accountExpire: [{required: true, message: '请填写请填写有效期', trigger: 'blur'}],
        phone: [{required: true, validator: pwdValidate, trigger: 'blur'}],
        // password: [
        //   {required: true, type: 'string', message: '请输入密码', trigger: 'blur'},
        //   {type: 'string', min: 8, max: 20, message: '请输入8-16位数字、字母组成，区分大小写', trigger: 'blur'}],
        imageUrl: [{required: true, message: '请上传公司logo', trigger: 'blur'}],
        licenseUrl: [{required: true, message: '营业执照', trigger: 'blur'}],
        branchAccountCount: [{required: true, message: '请填写分店账户数', trigger: 'blur'}],
        provinceId: [{required: true, message: '请选择行政区域省份', trigger: 'change'}],
        cityId: [{required: true, message: '请选择行政区域城市', trigger: 'change'}],
        districtId: [{required: true, message: '请选择行政区域区县', trigger: 'change'}],
        address: [
          {required: true, message: '请填写详细地址', trigger: 'blur'},
          {type: 'string', max: 50, message: '超过输入显示,请输入50字以内', trigger: 'blur'}
        ],
        lowestServicePrice: [{required: true, message: '请输入慢病包最低服务费', trigger: 'blur'}],
        lowestComplicationServicePrice: [{required: true, message: '请输入慢病包最低服务费', trigger: 'blur'}],
        lowestPrice: [{required: true, message: '请输入慢病包最低价格', trigger: 'blur'}],
        depositRatio: [{required: true, message: '请输入预付定金比例', trigger: 'blur'}],
        signRewardRatio: [{required: true, message: '请输入签约奖励比例', trigger: 'blur'}],
        detectRewardRatio: [{required: true, message: '请输入项目操作奖励比例', trigger: 'blur'}],
        consultDoctorRatio: [{required: true, message: '请输入完成医生自选奖励比例', trigger: 'blur'}],
        renewalRewardRatio: [{required: true, message: '请输入续约奖励比例', trigger: 'blur'}],
        txSignReward: [{required: true, message: '请输入天下医生签约奖励', trigger: 'blur'}],
        shortName: [{required: true, message: '请输入简称', trigger: 'blur'}],
      }
    }
  },
  methods: {
    modalClose() {
      this.$emit('update:visible', false); // 直接修改父组件的属性
    },
    // 选择公司性质
    changeNature(val) {
      this.hospitalType = val;
    },
    // 公司名称搜索
    remoteMethod(query) {
      let _this = this;
      if (query) {
        _this.loading2 = true
        this.post(this.api.regist.searchCompanyHospitalByES, {
          name: query
        }).then(({data: res}) => {
          if (res.code === '200') {
            _this.loading2 = false;
            _this.companyList = res.object;
          }
        });
        setTimeout(() => {
          _this.loading2 = false;
          _this.companyFilterList = _this.companyList.filter(item => item.name.indexOf(query) > -1);
        }, 2000);
      } else {
        this.companyFilterList = [];
      }
    },
    // 选择公司名称
    changeCompany(item) {
      let obj = this.companyFilterList.find(el => el.id === item)
      this.company.name = obj.name;
    },
    // 动态添加行 服务产品赠送
    handleAddProduct() {
      let res = this.company.servicePackageDtos;
      if (res.length > 0) {
        let item = res[res.length - 1];
        if (item.servicePackageId === '') {
          this.$message.error('请选择产品包名称');
          return
        }
        if (item.price === '') {
          this.$message.error('请输入价格');
          return
        }
        if (item.count === '') {
          this.$message.error('请输入赠送数量');
          return
        }
        this.company.servicePackageDtos.push({
          packageName: '', // 产品包名称
          servicePackageId: '', // 服务包id
          type: 1, // 服务包类型
          price: '', // 价格
          count: '', // 赠送数量
          newData: 1 // 否是新数据
        })

      } else {
        this.company.servicePackageDtos.push({
          packageName: '', // 产品包名称
          servicePackageId: '', // 服务包id
          type: 1, // 服务包类型
          price: '', // 价格
          count: '', // 赠送数量
          newData: 1 // 否是新数据
        })
      }
    },
    // 选择省
    selectChildren1(id) {
      this.company.cityId = '';
      this.company.districtId = '';
      this.post(this.api.baseArea, {id: this.company.provinceId}).then(res => {
        if (res.data.code === '200') {
          if (id === 0) {
            this.provinceList = res.data.object;
          } else {
            this.cityList = res.data.object;
          }
        }
      });
    },
    // 选择市
    selectChildren2(id) {
      this.company.cityId = id;
      this.company.districtId = '';
      this.post(this.api.baseArea, {id: id}).then(res => {
        if (res.data.code === '200') {
          this.districtList = res.data.object;
        }
      });
    },
    // 选择区
    selectChildren3(id) {
      this.company.districtId = id;
    },
    uploadLogoSuccess(res) {
      if (res.code === '200') {
        this.$message.success('上传成功');
        this.$set(this.company,'imageUrl',res.object[0])
      } else {
        this.$message.error('上传失败');
      }
    },
    uploadLicenseSuccess(res) {
      if (res.code === '200') {
        this.$message.success('上传成功');
        this.$set(this.company,'licenseUrl',res.object[0])
        // this.company.licenseUrl = res.object[0];
      } else {
        this.$message.error('上传失败');
      }
    },
    showError(file, fileList) {
      this.$Notice.warning({
        title: '文件大小超限',
        desc: "文件  " + file.name + " 太大，上传文件大小不能超过100M."
      });
    },
    // 删除服务产品赠送
    async handleDelete(index) {
      this.company.servicePackageDtos.splice(index, 1);
    },
    // 获取产品包名称列表
    async getProduceList() {
      const {data: res} = await this.post(this.api.ECG.getProductList, {
        status: 1
      })
      if (res.code === '200') {
        let resData = res.object.map(item => {
          return {
            servicePackageId: item.id,
            packageName: item.productName,
            ...item
          }
        })
        this.packageList = resData;
      }
    },
    // 选择产品包名称,根据id,匹配出对应的名称
    changePackageName(index, item) {
      let selectedObj = this.packageList.find(v => v.servicePackageId === item.servicePackageId);
      this.company.servicePackageDtos[index].packageName = selectedObj.packageName;
    },
    // 保存表单数据
    saveData() {
      this.$refs["formValidate"].validate(valid => {
        if (valid) {
          /* let res = this.company.servicePackageDtos
          let item = res[res.length - 1]
          if (item.servicePackageId === '') {
            this.$message.error('请选择产品包名称');
            return
          }
          if (item.price === '') {
            this.$message.error('请输入价格');
            return
          }
          if (item.count === '') {
            this.$message.error('请输入赠送数量');
            return
          } */
          // let copyCompany = JSON.parse(JSON.stringify(this.company))
          if (this.company.isOpenCdp==1&&(this.company.signRewardRatio+ this.company.detectRewardRatio + this.company.consultDoctorRatio + this.company.renewalRewardRatio) != 100) {
            this.$message.warning('签约奖励，完成操作，完成自选，续约比例累计必须100')
            return
          }
          if (this.company.id) { // 查看详情、编辑
            // this.company.account = '+86-' + this.company.account;
            // this.company.password = md5(this.company.account + this.company.password);
            this.company.companyId = this.company.id;
            this.post(this.api.company.editCompanty, this.company).then(res => {
              if (res.data.code === '200') {
                this.$message.success('保存成功');
                this.$parent.initTableData();
                this.modalClose();
                this.$refs["formValidate"].resetFields();
              }
            });
          } else { // 新增
            // this.company.account = '+86-' + this.company.account;
            // this.company.password = md5(this.company.account + this.company.password);
            this.post(this.api.company.addCompany, this.company).then(res => {
              if (res.data.code === '200') {
                this.$message.success('保存成功');
                this.$parent.initTableData();
                this.modalClose();
                this.company.id = '';
                this.$refs['formValidate'].resetFields();
              }
            });
          }
        }
      });
    },
    // 详情
    getDetail() {
      this.isDisabled = true;
      this.post(this.api.company.getCompanyDetail, {
        companyId: this.companyDialog.id
      }).then(res => {
        if (res.data.code === '200') {
          let resData = res.data.object;
          this.company = resData;
          // 公司名称
          this.company.hospitalId = resData.hospitalId;
          this.companyFilterList = [
            {id: resData.hospitalId, name: resData.name}
          ];
          if (!this.company.hasOwnProperty('servicePackageDtos')) {
            this.company.servicePackageDtos = [{
              packageName: '', // 产品包名称
              servicePackageId: '', // 服务包id
              type: 1, // 服务包类型
              price: '', // 价格
              count: '', // 赠送数量
              newData: 1 // 否是新数据
            }]
          }
          // if (this.companyDialog.account) {
          //   this.company.account = this.companyDialog.account.split("-")[1];
          // }
          this.company.hospitalType = resData.hospitalType;
          this.provinceList = this.company.provinceList;
          this.cityList = this.company.cityList;
          this.districtList = this.company.districtList;
          this.getProduceList(); // 服务产品赠送
        }
      });
    }
  },
  created() {
    this.fileLogoUploadAction = this.api.file.upload;
    this.fileLicenseUploadAction = this.api.file.upload;
    if (this.companyDialog) {
      this.title = '编辑';
      this.getDetail();
    } else {
      this.selectChildren1(0);
      this.getProduceList(); // 服务产品赠送
    }
  }
}
</script>
<style scoped lang="scss">
/deep/ .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 15px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 200px;
  height: 200px;
  line-height: 200px;
  text-align: center;
}

.avatar {
  width: 200px;
  height: 200px;
  display: block;
}
</style>
